home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_009 / proff / proff.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  315 lines

  1.  
  2.  
  3.  
  4. char *version = "v.1.1";
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include "debug.h"
  9. #include "defs.h"
  10. #include "lookup.h"
  11.  
  12.  
  13. /*
  14.  * G L O B A L S
  15.  *
  16.  */
  17. #ifndef vms
  18. #define globaldef
  19. #endif
  20.  
  21.     /* next available char; init = 0 */
  22. globaldef int bp = -1;
  23.     /* pushed-back characters */
  24. globaldef char buf[BUFSIZE];
  25.     /* stack of file descriptors */
  26. globaldef FILE *infile[NFILES];
  27.     /* current file is infile[level] */
  28. globaldef int level;
  29.     /* stack of output file descriptors */
  30. globaldef FILE *outfile[NFILES];
  31.     /* current output is outfile[olevel]; */
  32. globaldef int olevel;
  33.     /* current output file pointer */
  34. globaldef FILE *poutput;
  35.     /* number registers a..z */
  36. globaldef int nr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  38.     /* system registers a..z */
  39. globaldef int sr[26] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.               0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  41.     /* last char position in outbuf; init = 0 */
  42. globaldef int outp = 0;
  43.     /* width of text currently in outbuf; init = 0 */
  44. globaldef int outw = 0;
  45.     /* number of words in outbuf; init = 0 */
  46. globaldef int outwds = 0;
  47.     /* lines to be filled collect here */
  48. globaldef char outbuf[MAXOUT];
  49.                        /* word in outbuf; init=0 */
  50.     /* current output page number; init = 0 */
  51. globaldef int curpag = 0;
  52.     /* next output page number; init = 1 */
  53. globaldef int newpag = 1;
  54.     /* next line to be printed; init = 0 */
  55. globaldef int lineno = 0;
  56.     /* page length in lines; init = PAGELEN = 66 */
  57. globaldef int plval = PAGELEN;
  58.     /* page length save area */
  59. globaldef int savpl = PAGELEN;
  60.     /* margin before and including header */
  61. globaldef int m1val = 3;
  62.     /* margin after header */
  63. globaldef int m2val = 2;
  64.     /* margin after last text line */
  65. globaldef int m3val = 2;
  66.     /* bottom margin, including footer */
  67. globaldef int m4val = 3;
  68.     /* last live line on page, = plval-m3val-m4val */
  69. globaldef int bottom = PAGELEN - 5;
  70.     /* top of page title for even pages;init=NEWLINE */
  71. globaldef char ehead[MAXLINE];
  72.     /* top of page title for odd  pages;init=NEWLINE */
  73. globaldef char ohead[MAXLINE];
  74.     /* left,right margins for even header;init=inval,rmval */
  75. globaldef int ehlim[2] = { 0, PAGEWIDTH };
  76.     /* left,right margins for odd  header;init=inval,rmval */
  77. globaldef int ohlim[2] = { 0, PAGEWIDTH };
  78.     /* bot of page title for even pages;init=NEWLINE */
  79. globaldef char efoot[MAXLINE];
  80.     /* bot of page title for odd  pages;init=NEWLINE */
  81. globaldef char ofoot[MAXLINE];
  82.     /* left,right margins for even footer;init=inval,rmval */
  83. globaldef int eflim[2] = { 0, PAGEWIDTH };
  84.     /* left,right margins for odd  footer;init=inval,rmval */
  85. globaldef int oflim[2] = { 0, PAGEWIDTH };
  86.     /* flag for pausing between pages */
  87. globaldef int stopx = 0;
  88.     /* first page to begin printing with */
  89. globaldef int frstpg = 0;
  90.     /* last page to be printed */
  91. globaldef int lastpg = HUGE;
  92.     /* flag to indicate whether page should be printed */
  93. globaldef int print = YES;
  94.     /* number of blanks to offset page by; init = 0 */
  95. globaldef int  offset = 0;
  96.     /* verbose option; init = NO */
  97. globaldef int verbose = NO;
  98.     /* bolding option; init = YES; */
  99. globaldef char bolding = YES;
  100.     /* fill if YES; init = YES */
  101. globaldef int fill = YES;
  102.     /* current line spacing; init = 1 */
  103. globaldef int lsval = 1;
  104.     /* current indent; >= 0; init = 0 */
  105. globaldef int inval = 0;
  106.     /* current right margin; init = PAGEWIDTH = 60 */
  107. globaldef int rmval = PAGEWIDTH;
  108.     /* current temporary indent; init = 0 */
  109. globaldef int tival = 0;
  110.     /* number of lines to center; init = 0 */
  111. globaldef int ceval = 0;
  112.     /* flag for continuous center */
  113. globaldef char CEon = FALSE;
  114.     /* number of lines to underline; init = 0 */
  115. globaldef int ulval = 0;
  116.     /* flag for continuous underline */
  117. globaldef char ULon = FALSE;
  118.     /* number of lines to boldface; init = 0 */
  119. globaldef int boval = 0;
  120.     /* flag for continuous bolding */
  121. globaldef char BDon = FALSE;
  122.     /* justification types for heads and foots; */
  123.     /* init = LEFT, CENTER, RIGHT */
  124. globaldef int tjust[3] = { LEFT, CENTER, RIGHT };  
  125.     /* number of lines to blank suppress; init=0 */
  126. globaldef int bsval = 0;
  127.     /* right justify filled lines if YES; init=YES */
  128. globaldef int rjust = YES;
  129.     /* tab stops; init every 8 spaces */
  130. globaldef int tabs[INSIZE];
  131.     /* line control character; init = PERIOD */
  132. globaldef char cchar = '.';
  133.     /* universal escape - init = UNDERBAR */
  134. globaldef char genesc = '_';
  135.     /* character used to underline a BLANK; init = BLANK */
  136. globaldef char ulblnk = ' ';
  137.     /* scratch arrays for use by various routines */
  138. globaldef char tbuf1[MAXLINE];
  139. globaldef char tbuf2[MAXLINE];
  140. globaldef char tbuf3[MAXLINE];
  141. globaldef char ttl[MAXLINE];
  142.     /* flag to process runoff symbols only */
  143. globaldef char onlyrunoff = NO;
  144.     /* Flag to turn paging off */
  145. globaldef char paging = YES;
  146.     /* page number in roman numerals. Init = NO */
  147. globaldef char roman = NO;
  148.     /* autopar flag. Init = NO */
  149. globaldef char autopar = NO;
  150.     /* temporary indent value for autopar */
  151. globaldef int autoprv = 5;
  152.     /* hash tables for macros and variables */
  153. globaldef struct hashlist *macrotab[HASHMAX];
  154. globaldef struct hashlist *gentab[HASHMAX];
  155.     /* linked list entries for contents    */
  156. globaldef struct clist *chead = NULL;
  157. globaldef struct clist *clast = NULL;
  158.     /* keep track of what is done - VERBOSE */
  159. globaldef int p_txtlines = 0;
  160. globaldef int p_outlines = 0;
  161. globaldef int p_outpages = 0;
  162. globaldef int p_memoryus = 0;
  163.  
  164.  
  165.  
  166. /*
  167.  * M A I N L I N E   OF   P R O F F
  168.  *
  169.  */
  170.  
  171. main(argc,argv)
  172. int argc;
  173. char *argv[];
  174. {
  175.         int i,j,val,type;
  176.         char *p,c;
  177.         FILE *fp;
  178.  
  179.         for (i = 1; i < argc; i++) {
  180.                 p = argv[i];
  181.                 if (*p == '-') {
  182.                         ++p;
  183.                         if (isalpha(*p)) {
  184.                                 c = *p++;
  185.                                 switch(c) {
  186.  
  187. /* verbose stats */        case 'v':
  188.                 case 'V':
  189.                     verbose = TRUE;
  190.                     break;
  191. /* runoff only   */        case 'r':
  192.                 case 'R':
  193.                     onlyrunoff = TRUE;
  194.                     break;
  195. /* stop for page */             case 's':
  196.                                 case 'S':
  197.                                         stopx = 1;
  198.                                         break;
  199. /* page offset   */             case 'p':
  200.                                 case 'P':
  201.                                         if (*p == 'o' || *p == 'O') {
  202.                                                 p++;
  203.                                                 j = 0;
  204.                                                 val = getval(p, &j, &type);
  205.                                                 set(&offset, val, type, 0, 0,
  206.                                                     rmval - 1);
  207.                                         }
  208.                                         else
  209.                                                 usage();
  210.                                         break;
  211. /* include file  */         case 'i':
  212.                 case 'I': /* simulate .so <filename> */
  213.                     pbstr("\n");
  214.                     pbstr(p);
  215.                     pbstr(".so ");
  216.                     break;
  217.  
  218. /* disable some  */        case 'd':
  219.                 case 'D':
  220.                     switch (*p) {
  221.  
  222.                     case 'b':
  223.                     case 'B':
  224.                         bolding = NO;
  225.                         break;
  226.                     case 'p':
  227.                     case 'P':
  228.                         paging = NO;
  229.                         break;
  230.                     default:
  231.                         break;
  232.                     }
  233.                     break;
  234.  
  235. /* garbage       */             default:
  236.                                         usage();
  237.                                 }
  238.                         }
  239.                         else
  240.                      lastpg = atoi(p);
  241.                 }
  242.                 else if (*p == '+') {
  243.                         p++;
  244.                         if ((frstpg = atoi(p)) == 0)
  245.                                 usage();
  246.                 }
  247.                 else
  248.                         break;
  249.         }
  250.         if (i == argc)
  251.                 usage();
  252.         if ((fp = fopen(argv[i], "r")) == NULL) {
  253.                 fprintf(stderr, "%s: cannot open.\n",argv[i]);
  254.                 exit(1);
  255.         }
  256.         if (p = argv[++i]) {
  257.                 if ((outfile[0] = fopen(p, "w")) == NULL) {
  258.                         fprintf(stderr,"%s: cannot create.\n\n", p);
  259.                         exit(1);
  260.                 }
  261.     }
  262.     else
  263.         outfile[0] = stdout;
  264.             /* set output file level */
  265.     olevel = 0;
  266.     poutput = outfile[0];
  267.     /*
  268.      * some minor initialisation
  269.      */
  270.  
  271.     for (i = 0; i < INSIZE; i++)
  272.         if (i % 8 == 0)
  273.             tabs[i] = YES;
  274.         else
  275.             tabs[i] = NO;
  276.  
  277.     ehead[0] = '\n';
  278.     ehead[1] = EOS;
  279.     ohead[0] = '\n';
  280.     ohead[1] = EOS;
  281.     efoot[0] = '\n';
  282.     efoot[1] = EOS;
  283.     ofoot[0] = '\n';
  284.     ofoot[1] = EOS;
  285.  
  286.             /* initialise contents linked list */
  287.  
  288.     chead = (struct clist *) malloc(sizeof(struct clist));
  289.     clast = chead;
  290.     p_memoryus += sizeof(struct clist);
  291.  
  292.         doroff(fp);
  293.         brkeol();
  294.         if (plval <= 100 && (lineno > 0 | outp > 0))
  295.                 space(HUGE);
  296.         putchar('\n');
  297.  
  298.     if(verbose) {
  299.         fprintf(stderr,"proff read in %6d textlines to produce\n",
  300.             p_txtlines);
  301.         fprintf(stderr,"              %6d lines\n",
  302.             p_outlines);
  303.         fprintf(stderr,"              %6d pages of formatted text.\n",
  304.             p_outpages);
  305.         fprintf(stderr,"\n%d bytes of memory was required\n",
  306.             p_memoryus);
  307.         fprintf(stderr,"for internal tables and lists.\n");
  308.     }
  309. #ifdef vms
  310.         exit(1);
  311. #else
  312.         exit(0);
  313. #endif
  314. }
  315.